﻿using AgencyManagerSystem.Model;
using System;
using System.Collections.Generic;
using System.Linq;

namespace AgencyManagerSystem.DataFetcher
{
    public class RetailMemberFetcher:BaseFetcher<RetailMemberModel>
    {

        public RetailMemberFetcher() : base()
        {

        }
        public RetailMemberModel GetByCode(int retail,string code)
        {
            Condition[] conditions = new Condition[] { new Condition() { Key = "Code", Op = "=", Value = code }
                                                      ,new Condition() { Key = "Retail", Op = "=", Value = retail }};
            var list = List(conditions);
            if (list.Count > 0)
                return list.First();
            else
                return null;
        }
        public RetailMemberModel GetByUser(int user)
        {
            Condition[] conditions = new Condition[] { new Condition() { Key = "User", Op = "=", Value = user } };
            var list = List(conditions);
            if (list.Count > 0)
                return list.First();
            else
                return null;
        }
        public IList<RetailMemberModel> ListByRetail(int retail)
        {
            Condition[] conditions = new Condition[] { new Condition() { Key = "Retail", Op = "=", Value = retail } };
            var list = List(conditions);
            return list;
        }

        public IList<RetailMemberModel> ListDetail(int mainId)
        {
            var list = ListDetail(mainId, 0, 1000);
            return list;
        }

        public IList<RetailMemberModel> ListDetail(int mainId, int pos, int size)
        {
            Condition[] conditions = Condition.MakeCondition(String.Format("Retail={0}", mainId));
            var list = List(conditions,pos,size);
            throw new System.NotImplementedException();
        }
    }
}
